package com.tsinghuabigdata.edu.ddmath.util;


import android.text.TextUtils;
import android.util.Log;

import com.tsinghuabigdata.edu.ddmath.ZxApplication;
import com.tsinghuabigdata.edu.ddmath.bean.BensCourse;
import com.tsinghuabigdata.edu.ddmath.bean.MonthSumbitedItem;
import com.tsinghuabigdata.edu.ddmath.bean.MyCourse;
import com.tsinghuabigdata.edu.ddmath.bean.Records;
import com.tsinghuabigdata.edu.ddmath.bean.StudentsBean;
import com.tsinghuabigdata.edu.ddmath.bean.SubmitQuestion;
import com.tsinghuabigdata.edu.ddmath.module.onlineTutoring.bean.OnlineTutoring;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/2/18.
 */


public class DataUtils {

    private static final String TAG = "Utils";

    public static List<BensCourse> getBeansCourse() {
        List<BensCourse> allList = new ArrayList<BensCourse>();
        for (int m = 0; m < 3; m++) {
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 4; j++) {
                    BensCourse vo = new BensCourse();
                    if (m == 0) {
                        vo.setGrade("七年级");
                    } else if (m == 1) {
                        vo.setGrade("八年级");
                    } else if (m == 2) {
                        vo.setGrade("九年级");
                    }
                    if (i == 0) {
                        vo.setTime("春季");
                    } else {
                        vo.setTime("暑期");
                    }
                    if (j == 0) {
                        if (i == 0) {
                            vo.setKind("同步提分");
                        } else {
                            vo.setKind("衔接提分");
                        }
                        for (int k = 0; k < 7; k++) {
                            if (k == 0) {
                                vo.setTag("LV1基础班");
                            } else if (k == 1) {
                                vo.setTag("LV2基础班");
                            } else if (k == 2) {
                                vo.setTag("LV3基础班");
                            } else if (k == 3) {
                                vo.setTag("LV1培优班");
                            } else if (k == 4) {
                                vo.setTag("LV2培优班");
                            } else if (k == 5) {
                                vo.setTag("LV3培优班");
                            } else if (k == 6) {
                                vo.setTag("满分班");
                            }
                            BensCourse bensCourse = new BensCourse(vo);
                            allList.add(bensCourse);
                        }
                        continue;
                    } else if (j == 1) {
                        vo.setKind("专题突破");
                    } else if (j == 2) {
                        vo.setKind("综合升华");
                    } else if (j == 3) {
                        vo.setKind("名校冲刺");
                    }
                    allList.add(vo);
                }
            }
        }
        return allList;
    }

    public static List<StudentsBean> getOtherStudents(List<StudentsBean> studentsList, String studentId) {
        Log.i(TAG, "studentsList.size()=" + studentsList.size());
        List<StudentsBean> otherList = new ArrayList<StudentsBean>();
        for (int i = 0; i < studentsList.size(); i++) {
            StudentsBean studentsBean = studentsList.get(i);
            if (!studentId.equals(studentsBean.getStudentId())) {
                otherList.add(studentsBean);
            }
        }
        Collections.shuffle(otherList);
        Log.i(TAG, "otherList.size()=" + otherList.size());
        return otherList;
    }

    public static List<Records> select(List<MyCourse> resList) {
        List<Records> recordsList = new ArrayList<Records>();
        List<MyCourse> list = new ArrayList<MyCourse>();
        String lastDate = resList.get(0).getDate().substring(0, 7);
        for (int i = 0; i < resList.size(); i++) {
            MyCourse myCourse = resList.get(i);
            String date = myCourse.getDate().substring(0, 7);
            if (!date.equals(lastDate)) {
                Log.i(TAG, "lastDate=" + lastDate + "date=" + date);
                String month = lastDate.substring(0, 4) + "年" + lastDate.substring(5, 7) + "月";
                List<MyCourse> teamList = new ArrayList<MyCourse>();
                teamList.addAll(list);
                Log.i(TAG, "teamList.size() =" + teamList.size());
                Records records = new Records(month, teamList);
                recordsList.add(records);
                list.clear();
                lastDate = date;
            }
            list.add(myCourse);
            if (i == resList.size() - 1) {
                String month = lastDate.substring(0, 4) + "年" + lastDate.substring(5, 7) + "月";
                List<MyCourse> teamList = new ArrayList<MyCourse>();
                teamList.addAll(list);
                Records records = new Records(month, teamList);
                recordsList.add(records);
            }
        }
        Log.i(TAG, "recordsList.size()=" + recordsList.size());
        return recordsList;
    }

    public static String getFormatName(String reallyName) {
        if (TextUtils.isEmpty(reallyName)) {
            return null;
        } else if (reallyName.length() > 6) {
            return reallyName.substring(0, 6) + "...";
        } else {
            return reallyName;
        }

    }

    public static String  getQuestionIds(HashMap<String, Boolean> qustionMap) {
        if (qustionMap.keySet().size() == 0){
            return "";
        }
        Iterator iter = GlobalData.getQustionMap().entrySet().iterator();
        StringBuilder sb = new StringBuilder();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            String key = (String) entry.getKey();
            sb.append(key);
            sb.append(",");
        }
        sb.deleteCharAt(sb.length()-1);
        return sb.toString();
    }

    public static List<MonthSumbitedItem> selectDoudouWork(List<SubmitQuestion> resList) {
        List<MonthSumbitedItem> monthList = new ArrayList<MonthSumbitedItem>();
        List<SubmitQuestion> list = new ArrayList<SubmitQuestion>();
        String lastDate = resList.get(0).getStartTime().substring(0, 7);
        for (int i = 0; i < resList.size(); i++) {
            SubmitQuestion submitQuestion = resList.get(i);
            String date = submitQuestion.getStartTime().substring(0, 7);
            if (!date.equals(lastDate)) {
                Log.i(TAG, "lastDate=" + lastDate + "date=" + date);
                String month = lastDate.substring(0, 4) + "年" + lastDate.substring(5, 7) + "月";
                List<SubmitQuestion> teamList = new ArrayList<SubmitQuestion>();
                teamList.addAll(list);
                Log.i(TAG, "teamList.size() =" + teamList.size());
//                Records records = new Records(month, teamList);
                MonthSumbitedItem monthSumbitedItem = new MonthSumbitedItem(month, teamList);
                monthList.add(monthSumbitedItem);
                list.clear();
                lastDate = date;
            }
            list.add(submitQuestion);
            if (i == resList.size() - 1) {
                String month = lastDate.substring(0, 4) + "年" + lastDate.substring(5, 7) + "月";
                List<SubmitQuestion> teamList = new ArrayList<SubmitQuestion>();
                teamList.addAll(list);
                MonthSumbitedItem monthSumbitedItem = new MonthSumbitedItem(month, teamList);
                monthList.add(monthSumbitedItem);
            }
        }
        Log.i(TAG, "monthList.size()=" + monthList.size());
        return monthList;
    }


}
